package com.bawei.hgshop.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.bawei.hgshop.entity.Spec;
import com.bawei.hgshop.entity.SpecOption;

public interface SpecMapper {

	@Insert("insert into hg_spec(spec_name) values(#{specName})")
	//返回自增的主键
	@Options(useGeneratedKeys = true,keyColumn = "id",keyProperty = "id")
	int add(Spec spec);

	@Update("update hg_spec set spec_name=#{specName} where id=#{id}")
	int update(Spec spec);

	@Update("update hg_spec_option set option_name=#{optionName},orders=#{orders} where id=#{id}")
	int updateOptions(SpecOption x);

	@Insert("insert into hg_spec_option(spec_id,option_name,orders) values(#{specId},#{optionName},#{orders})")
	int addOptions(SpecOption x);

	int delOptions(int ...ids);
	
	int delOptionById(int id);

	List<Spec> list();

	int del(int[] ids);
	
	Spec findById(int id);

	@Select("select * from hg_spec order by spec_name")
	List<Spec> listAll();

	@Select("select * from hg_spec_option where spec_id=#{value} order by orders")
	List<SpecOption> listOptionsBySpecId(int specId);

	
	List<Spec> listBySpuId(int spuId);

}
